# Python 2.6.4
# Project Euler, Problem 44
# Copyright 2010 Talha Zaman

from math import sqrt
def P(n): return n*(3*n-1)/2
def ispen(n):
    check = (sqrt(24*n+1)+1)/6
    return check == int(check)

ans = 0
for i in range(1,10000):
    for j in range(1,i):
        pk = P(i) - P(j)
        if pk!=P(j) and ispen(pk) and ispen(P(i)+P(j)):
            ans = P(i) - P(j)
            break
    if ans: break
print ans
